package co.edu.usbcali.egrapico.vista.tools;

import co.edu.usbcali.egrapico.vista.FrmPrincipal;
import co.edu.usbcali.egrapico.vista.ambient.LabelIdeOpe;
import co.edu.usbcali.egrapico.vista.ambient.LabelMethod;
import co.edu.usbcali.egrapico.vista.ambient.PanelPrecedentMsg;

public class JPanelTranferHandlerPrecedentMsg extends StringTransferHandler implements java.io.Serializable {

    protected void importString(javax.swing.JComponent c, String str) {
        PanelPrecedentMsg target = (PanelPrecedentMsg) c;
        try {
            target.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
        javax.swing.ImageIcon I10 = new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/value.gif"));
        javax.swing.ImageIcon I11 = new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/variable.gif"));
        javax.swing.ImageIcon I12 = new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/argument.gif"));
        javax.swing.ImageIcon I13 = new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/senderOperator.gif"));
        javax.swing.ImageIcon I14 = new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/method.gif"));
        LabelIdeOpe label = new LabelIdeOpe();
        LabelMethod labe2 = new LabelMethod();
        if (str.equals("Value")) {
            label.setIcon(I10);
            label.setHorizontalTextPosition(javax.swing.JLabel.CENTER);
            label.setVerticalTextPosition(javax.swing.JLabel.BOTTOM);
            label.setName(str);
            java.awt.Component cArgument = target.findComponentAt(target.getMousePosition());
            if (cArgument instanceof LabelIdeOpe && target.getmethodCount() == 1) {
                int m = 0;
                if (target.getLPaneMethod().getComponent(0) instanceof LabelMethod) {
                    m = FrmPrincipal.getMethod(((LabelMethod) target.getLPaneMethod().getComponent(0)).getName()).getFrame().getArguments();
                } else //entonses es el sugundo elemento
                {
                    m = FrmPrincipal.getMethod(((LabelMethod) target.getLPaneMethod().getComponent(1)).getName()).getFrame().getArguments();
                }
                if (m > target.getPuertos() && ((LabelIdeOpe) cArgument).getIcon().toString().endsWith("argumentP.gif")
                        && !(target.getLPane().findComponentAt(((LabelIdeOpe) cArgument).getX() + 100, ((LabelIdeOpe) cArgument).getY()) instanceof LabelIdeOpe)) {
                    label.setLocation(((LabelIdeOpe) cArgument).getX() + 100, ((LabelIdeOpe) cArgument).getY());
                    label.setSize(80, 80);
                    label.setId("id2");
                    target.setYscroll();
                    target.addLayeredPane(label);
                }
            } else if (target.findComponentAt(target.getMousePosition()) instanceof javax.swing.JPanel && target.getidentificador() < 1) {
                label.setId("id4");
                label.setSize(80, 80);
                label.setLocation(30, 120);
                target.addLayeredPane(label);

            }
        } else if (str.equals("Variable")) {
            label.setIcon(I11);
            label.setHorizontalTextPosition(javax.swing.JLabel.CENTER);
            label.setVerticalTextPosition(javax.swing.JLabel.BOTTOM);
            label.setName(str);
            java.awt.Component cArgument = target.findComponentAt(target.getMousePosition());
            if (cArgument instanceof LabelIdeOpe && target.getmethodCount() == 1) {
                int m = 0;
                if (target.getLPaneMethod().getComponent(0) instanceof LabelMethod) {
                    m = FrmPrincipal.getMethod(((LabelMethod) target.getLPaneMethod().getComponent(0)).getName()).getFrame().getArguments();
                } else //entonses es el sugundo elemento
                {
                    m = FrmPrincipal.getMethod(((LabelMethod) target.getLPaneMethod().getComponent(1)).getName()).getFrame().getArguments();
                }
                if (m > target.getPuertos() && ((LabelIdeOpe) cArgument).getIcon().toString().endsWith("argumentP.gif")
                        && !(target.getLPane().findComponentAt(((LabelIdeOpe) cArgument).getX() + 100, ((LabelIdeOpe) cArgument).getY()) instanceof LabelIdeOpe)) {
                    label.setLocation(((LabelIdeOpe) cArgument).getX() + 100, ((LabelIdeOpe) cArgument).getY());
                    label.setSize(80, 80);
                    label.setId("id2");
                    target.setYscroll();
                    target.addLayeredPane(label);
                }
            } else if (target.findComponentAt(target.getMousePosition()) instanceof javax.swing.JPanel && target.getidentificador() < 1) {
                label.setId("id4");
                label.setSize(80, 80);
                label.setLocation(30, 120);
                target.addLayeredPane(label);

            }
        } else if (str.equals("Argument")) {
            label.setIcon(I12);
            label.setHorizontalTextPosition(javax.swing.JLabel.CENTER);
            label.setVerticalTextPosition(javax.swing.JLabel.BOTTOM);
            label.setName(str);
            java.awt.Component cArgument = target.findComponentAt(target.getMousePosition());
            if (cArgument instanceof LabelIdeOpe && target.getmethodCount() == 1) {
                int m = 0;
                if (target.getLPaneMethod().getComponent(0) instanceof LabelMethod) {
                    m = FrmPrincipal.getMethod(((LabelMethod) target.getLPaneMethod().getComponent(0)).getName()).getFrame().getArguments();
                } else //entonses es el sugundo elemento
                {
                    m = FrmPrincipal.getMethod(((LabelMethod) target.getLPaneMethod().getComponent(1)).getName()).getFrame().getArguments();
                }
                if (m > target.getPuertos() && ((LabelIdeOpe) cArgument).getIcon().toString().endsWith("argumentP.gif")
                        && !(target.getLPane().findComponentAt(((LabelIdeOpe) cArgument).getX() + 100, ((LabelIdeOpe) cArgument).getY()) instanceof LabelIdeOpe)) {
                    label.setLocation(((LabelIdeOpe) cArgument).getX() + 100, ((LabelIdeOpe) cArgument).getY());
                    label.setSize(80, 80);
                    label.setId("id2");
                    target.setYscroll();
                    target.addLayeredPane(label);
                }
            } else if (target.findComponentAt(target.getMousePosition()) instanceof javax.swing.JPanel && target.getidentificador() < 1) {
                label.setId("id4");
                label.setSize(80, 80);
                label.setLocation(30, 120);
                target.addLayeredPane(label);

            }
        } else if (str.equals("Sender")) {
            label.setIcon(I13);
            label.setHorizontalTextPosition(javax.swing.JLabel.CENTER);
            label.setVerticalTextPosition(javax.swing.JLabel.BOTTOM);
            label.setName(str);
            java.awt.Component cArgument = target.findComponentAt(target.getMousePosition());
            if (cArgument instanceof LabelIdeOpe && target.getmethodCount() == 1) {
                int m = 0;
                if (target.getLPaneMethod().getComponent(0) instanceof LabelMethod) {
                    m = FrmPrincipal.getMethod(((LabelMethod) target.getLPaneMethod().getComponent(0)).getName()).getFrame().getArguments();
                } else //entonses es el sugundo elemento
                {
                    m = FrmPrincipal.getMethod(((LabelMethod) target.getLPaneMethod().getComponent(1)).getName()).getFrame().getArguments();
                }
                if (m > target.getPuertos() && ((LabelIdeOpe) cArgument).getIcon().toString().endsWith("argumentP.gif")
                        && !(target.getLPane().findComponentAt(((LabelIdeOpe) cArgument).getX() + 100, ((LabelIdeOpe) cArgument).getY()) instanceof LabelIdeOpe)) {
                    label.setLocation(((LabelIdeOpe) cArgument).getX() + 100, ((LabelIdeOpe) cArgument).getY());
                    label.setSize(80, 80);
                    label.setId("id2");
                    target.setYscroll();
                    target.addLayeredPane(label);
                }
            } else if (target.findComponentAt(target.getMousePosition()) instanceof javax.swing.JPanel && target.getidentificador() < 1) {
                label.setId("id4");
                label.setSize(80, 80);
                label.setLocation(30, 120);
                target.addLayeredPane(label);

            }
        } else if (FrmPrincipal.esMetodo(str)) {
            labe2.setIcon(I14);
            labe2.setHorizontalTextPosition(javax.swing.JLabel.CENTER);
            labe2.setVerticalTextPosition(javax.swing.JLabel.BOTTOM);
            labe2.setName(str);
            if (target.getLPaneMethod().getMousePosition() != null && target.getmethodCount() == 0) {
                labe2.setLocation(30, 30);
                labe2.setSize(90, 90);
                target.addLayeredPane(labe2);
            }
        }
    }
}
